package com.zlx.ssm.controller;

import com.mysql.cj.util.StringUtils;
import com.zlx.ssm.service.impl.DeleServiceimpl;
import com.zlx.ssm.vo.DateInfo;
import com.zlx.ssm.vo.ResultDateVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@Slf4j
public class DeleController {

    @Autowired
    private DeleServiceimpl deleServiceimpl;

    @RequestMapping("/dele/admin/{id}")
    @ResponseBody
    public ResultDateVo deleEmplo(@PathVariable("id") String id) {


        ResultDateVo resultDateVo = new ResultDateVo();
        if ("".equals(id) || id == null) {
            resultDateVo.setCode("-1");
            resultDateVo.setMsg("参数错误");
        }

        //调用servcie删除ID
        int i = deleServiceimpl.delectById(id);

        if (i > 0) {
            resultDateVo.setCode("0");
            resultDateVo.setMsg("删除成功");
            return resultDateVo;
        } else {
            resultDateVo.setCode("-1");
            resultDateVo.setMsg("删除失败");
            return resultDateVo;
        }


    }

    @RequestMapping("/dele/info")
    @ResponseBody
    public ResultDateVo deleInfoTo(@RequestBody List<DateInfo> infoList) {
        ResultDateVo resultDateVo = new ResultDateVo();

        log.info("删除的数据" + infoList);

        //调用批量删除语句
        int i = deleServiceimpl.deleNotListId(infoList);

        if (i > 0) {
            resultDateVo.setCode("0");
            resultDateVo.setMsg("删除成功");
            return resultDateVo;
        } else {
            resultDateVo.setCode("-1");
            resultDateVo.setMsg("删除失败");
            return resultDateVo;
        }


    }
}
